/*
 * @lc app=leetcode.cn id=46 lang=swift
 *
 * [46] 全排列
 */

// @lc code=start
class Solution {
    func permute(_ nums: [Int]) -> [[Int]] {
        var res: [[Int]] = []
        func def(_ nums: [Int], _ track: [Int]) {
            if track.count == nums.count {
                res.append(track)
                return
            }
            for i in 0..<nums.count {
                if track.contains(nums[i]) {
                    continue
                }
                var newTrack = track
                newTrack.append(nums[i])
                def(nums, newTrack)
            }
        }
        def(nums, [Int]())
        return res
    }
}
// @lc code=end

